import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Consts {
  /***首页Card中提示Tag的风格
   * true:Chip风格
   * false:圆形进度风格
   */
  static const bool HOME_PAGE_TAG_STYLE = true;

  /***当电表为负数时,电表计数方式
   * true:置为0
   * false:当成电表倒转,以计算出使用量
   */
  static const bool NEGATIVE_BILL_CALCULATE_WAY = true;

  final int yearlimit = 100;
  static const List<Widget> monthList = [
    Center(child: Text("1月")),
    Center(child: Text("2月")),
    Center(child: Text("3月")),
    Center(child: Text("4月")),
    Center(child: Text("5月")),
    Center(child: Text("6月")),
    Center(child: Text("7月")),
    Center(child: Text("8月")),
    Center(child: Text("9月")),
    Center(child: Text("10月")),
    Center(child: Text("11月")),
    Center(child: Text("12月")),
  ];

  static List<Widget> numberList = [
    Center(
      child: Text("0", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("1", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("2", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("3", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("4", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("5", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("6", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("7", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("8", style: _checkingScreenPickerText),
    ),
    Center(
      child: Text("9", style: _checkingScreenPickerText),
    ),
  ];

  static List<Widget> yearList = [];

  static TextStyle titleText = TextStyle(
      decoration: TextDecoration.none,
      fontSize: 45.sp,
      fontFamily: "素材集市社会体",
      // fontWeight: FontWeight.w400,
      color: Colors.black87);

  static final TextStyle _checkingScreenPickerText = TextStyle(
      fontSize: 35.sp, fontWeight: FontWeight.w700, color: Colors.black87);

  initalYearList() {
    int year = DateTime.now().year;
    int yearTemp = (year - (yearlimit / 2).toInt());
    for (int i = 0; i <= yearlimit; i++) {
      String yearTempString = (yearTemp + i).toString();
      yearList.add(Center(child: Text(yearTempString)));
    }
  }

  int getNowMonthIndex() {
    return DateTime.now().month - 1;
  }

  int getMonthIndex(int month) {
    return month - 1;
  }

  int getMonthByIndex(int index) {
    return index + 1;
  }

  int getNowYearIndex() {
    return (yearlimit / 2).toInt();
  }

  int getYearIndex(int year) {
    int zeroIndex = DateTime.now().year - (yearlimit / 2).toInt();
    return year - zeroIndex;
  }

  int getYearByIndex(int index) {
    int year = DateTime.now().year;
    year = year - (yearlimit / 2).toInt();
    return year + index;
  }

  //计算当电表满了,倒转的情况,
  //因为电表倒转了,所以要根据上月的数,位数加1,算出差值,再加上当月读数
  int calculateBillFulSituation(int lastMonth, int currentMonth) {
    //获取上月读数位数
    int digitCount = lastMonth.toString().length;

    // 构建一个数字，位数增加一位，新增的位数设置为1，其余位数为0
    int temp = pow(10, digitCount).toInt();
    // 返回b - a
    return temp - lastMonth + currentMonth;
  }
}
